package com.jt9003.utils;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;



public class P_NamberUtil {

    //当前接诊人数，默认是0
    public static int amPatientNambers = 0;
    public static int pmPatientNambers = 0;
    public static int nightPatientNambers = 0;
    public static int orderPatientNambers = 0;

    //设置上午,下午,晚上接诊人数，默认是50
    public static int amPatientNamber = 50;
    public static int pmPatientNamber = 50;
    public static int nightPatientNamber = 50;
    //设置区分上午下午和晚上的时间  上午下午晚上分别指3个上班的时间
    public static String am1;
    public static String am2;
    public static String pm1;
    public static String pm2;
    public static String night1;
    public static String night2;

    //静态代码块
    static {
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH) + 1;//注意月份
        int day = now.get(Calendar.DAY_OF_MONTH);
        am1 = year+"-"+month+"-"+day+" "+"06:00:00";
        am2 = year+"-"+month+"-"+day+" "+"12:00:59";
        pm1 = year+"-"+month+"-"+day+" "+"12:01:00";
        pm2 = year+"-"+month+"-"+day+" "+"19:00:59";
        night1 = year+"-"+month+"-"+day+" "+"19:01:00";
        night2 = year+"-"+month+"-"+day+" "+"05:59:59";
    }


    /**
     * 设置上午下午晚上的时间
     * @param date
     * @param dateName
     * @return
     * @throws ParseException
     */
    public static Boolean setDate(String date,int dateName) throws ParseException {
            boolean set = true;
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH) + 1;//注意月份
        int day = now.get(Calendar.DAY_OF_MONTH);
            switch (dateName){
                case 1:
                    am1 = year+"-"+month+"-"+day+" "+date;
                    break;
                case 2:
                    am2 = year+"-"+month+"-"+day+" "+date;
                    break;
                case 3:
                    pm1 = year+"-"+month+"-"+day+" "+date;
                    break;
                case 4:
                    pm2 = year+"-"+month+"-"+day+" "+date;
                    break;
                case 5:
                    night1 = year+"-"+month+"-"+day+" "+date;
                    break;
                case 6:
                    night2 = year+"-"+month+"-"+day+" "+date;
                    break;
                default:
                    set=false;
            }
        return set;
    }


    /**
     * 设置接诊人数
     * @param patientNamber
     * @param patientNamberName
     * @return
     */
    public static boolean setPatientNamber(int patientNamber,int patientNamberName){
        boolean check = true;
        switch (patientNamberName){
            case 1:
                amPatientNamber=patientNamber;
                break;
            case 2:
                pmPatientNamber=patientNamber;
                break;
            case 3:
                nightPatientNamber=patientNamber;
                break;
            default:
                check = false;
                break;
        }
        return check;
    }

    /**
          * 判断时间是否在时间段内
          * @param nowTime
          * @param beginTime
          * @param endTime
          * @return
          */
    public static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        if (date.after(begin) && date.before(end)) {
            return true;
        } else if (nowTime.compareTo(beginTime) == 0 || nowTime.compareTo(endTime) == 0) {
            return true;
        } else {
            return false;
        }
    }



}
